﻿package com.obj{
	import com.adobe.serialization.json.JSON;
	import com.facebook.graph.FacebookDesktop;
	import com.facebook.graph.data.FacebookSession;
	import com.facebook.graph.net.FacebookRequest;
	
	import air.update.ApplicationUpdater;
	import air.update.ApplicationUpdaterUI;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import air.update.events.UpdateEvent;
	import flash.filesystem.File;
	import flash.net.URLRequestHeader;
	import flash.net.URLRequestDefaults;
	import com.facebook.graph.Facebook;
	import com.facebook.graph.core.FacebookLimits;
	
	public class FlashDesktopMain extends Sprite {
		
		protected static const APP_ID:String = "360803593947953"; // Your App ID.
		protected static const APP_ORIGIN:String = "http://www.lukits.com"; //The site URL of your application (specified in your app settings); needed for clearing cookie when logging out
		private var _appUpdater:ApplicationUpdaterUI = new ApplicationUpdaterUI();
		private var currentStatus:String;
		
		public function FlashDesktopMain() {	
			
			configUI();
		}
		
		protected function configUI():void {
			FacebookDesktop.manageSession = false;
			FacebookDesktop.init(APP_ID,loginHandler);
			_appUpdater.configurationFile = new File("app:/update_config.xml");
			_appUpdater.initialize();
			_appUpdater.addEventListener(UpdateEvent.INITIALIZED,updateInitializedHandler);
						
		}

		
			

			protected function updateInitializedHandler(event:UpdateEvent):void
			{
				//_appUpdater.checkNow();
			}
			protected function loginHandler(success:Object,fail:Object):void
			{
				
				if(success){
					txtName.text = success.user.name
					/*currentStatus="loggedin";
					nameLbl.text=success.user.name;
					//userImg.source=FacebookDesktop.getImageUrl(success.uid,"small");
					birthdayLbl.text=success.user.birthday;*/
					FacebookDesktop.api("/me/statuses",getStatusHandler);
					
				}
				if(fail){
					//
					}
				
			}
			protected function login():void
			{
				FacebookDesktop.login(loginHandler,["user_birthday","read_stream","publish_stream"]);
			}
			protected function logout():void
			{
				FacebookDesktop.logout();
				currentStatus="loggedout";
			}
			protected function getStatusHandler(result:Object, fail:Object):void
			{
				trace(result[0].message);	
			}
			protected function submitPost():void
			{
					var values:Object = { 
					name:"This is my title", 
					link:"http://example.com", 
					picture:"http://example.com/icon-75x75.gif", 
					caption:"this is a caption", 
					description:"this is a long description", 
					message:"This is a test message. There are many like it but this one is mine.", 
					actions: 
					{ 
					name:"Crazy extra thing", 
					link:"http://example.com" 
					} 
					
					}; 
					
					//FacebookDesktop.api(_user + "/feed", handleSubmitFeed, values, URLRequestMethod.POST); 
			}
			protected function submitPostHandler(result:Object,fail:Object):void
			{
				FacebookDesktop.api("/me/statuses",getStatusHandler);
			}
		
	}
}